package rawengine.entity;

import rawengine.gamecore.GameCore;
import rawengine.timer.TimeAccumulator;

public abstract class Entity {
	
	private int id;
	private String name;
	private boolean visible;
	private boolean alive;
	private boolean collidable;
	private int objectType;
	private int lifeTimeLength;
	private TimeAccumulator lifetimeTimer;
	
	private CollisionType collisionType;
	
	
	public Entity(String name)
	{
		setName(name);
		setId(-1);
		setAlive(true);
		setCollidable(true);
		setCollisionType(CollisionType.RECTANGLE);
	}


	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}


	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}


	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}


	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}


	/**
	 * @param visible the visible to set
	 */
	public void setVisible(boolean visible) {
		this.visible = visible;
	}


	/**
	 * @return the visible
	 */
	public boolean isVisible() {
		return visible;
	}


	/**
	 * @param alive the alive to set
	 */
	public void setAlive(boolean alive) {
		this.alive = alive;
	}


	/**
	 * @return the alive
	 */
	public boolean isAlive() {
		return alive;
	}


	/**
	 * @param objectType the objectType to set
	 */
	public void setObjectType(int objectType) {
		this.objectType = objectType;
	}


	/**
	 * @return the objectType
	 */
	public int getObjectType() {
		return objectType;
	}


	/**
	 * @param lifetimeLength the lifetimeLength to set in milliseconds
	 */
	public void setLifeTime(int lifetimeLength) {
		this.lifeTimeLength = lifetimeLength;
		lifetimeTimer = new TimeAccumulator();
		lifetimeTimer.init(GameCore.timeHandler, lifetimeLength);
	}
	
	public void updateLifeTime()
	{
		if(lifetimeTimer != null)
		{
			lifetimeTimer.update();
		}
	}


	/**
	 * @return the lifetimeLength
	 */
	public int getLifeTime() {
		return lifeTimeLength;
	}


	/**
	 * @param lifetimeTimer the lifetimeTimer to set
	 */
	public boolean lifeTimeExpired() {
		if(getLifeTime() > 0)
		{
			return lifetimeTimer.ended();
		}
		return false;
	}

	 /**
    Clones this Sprite. Does not clone position or velocity
    info.
	  */
	public abstract Object clone();
	
	public abstract void update();
	
	public abstract void draw(float x, float y);


	/**
	 * @param collidable the collidable to set
	 */
	public void setCollidable(boolean collidable) {
		this.collidable = collidable;
	}


	/**
	 * @return the collidable
	 */
	public boolean isCollidable() {
		return collidable;
	}


	/**
	 * @param collisionType the collisionType to set
	 */
	public void setCollisionType(CollisionType collisionType) {
		this.collisionType = collisionType;
	}


	/**
	 * @return the collisionType
	 */
	public CollisionType getCollisionType() {
		return collisionType;
	} 
}
